package com.vvv.designpattern.ticket.director;

import com.vvv.designpattern.ticket.builder.CompanyTicketBuilder;
import com.vvv.designpattern.ticket.builder.PersonalTicketBuilder;
import org.springframework.stereotype.Component;

/**
 * @author vvv
 * @date 2023-11-25 14 52
 * discription建造者模式：导演类负责指导builder进行对象的创建
 * 说人话就是：导演类是暴露给调用者的，封装调用具体建造类的set方法，和返回建造对象的方法，让调用者一行代码获取创建的对象，懂？
 *
 * 我们发现一般暴露给调用者的都是要加@Component注解的
 */
@Component
public class Director extends AbstractDirector{
    @Override
    public Object buildTicket(String type, String product, String content, String title, String bankInfo, String taxId) {

        if ("person".equals(type)) {
            PersonalTicketBuilder personalTicketBuilder = new PersonalTicketBuilder();
            personalTicketBuilder.setCommonInfo(title, product, content);
            return personalTicketBuilder.buildTicket();
        } else if ("company".equals(type)) {
            CompanyTicketBuilder companyTicketBuilder = new CompanyTicketBuilder();
            companyTicketBuilder.setCommonInfo(title, product, content);
            companyTicketBuilder.setBankInfo(bankInfo);
            companyTicketBuilder.setTaxId(taxId);
            return companyTicketBuilder.buildTicket();
        }
        throw new UnsupportedOperationException("不支持的发票类型");
    }
}
